//
//  CTCConsultAnsCell.m
//  CTC
//
//  Created by 边文辉 on 2017/3/22.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "CTCConsultAnsCell.h"


@interface CTCConsultAnsCell ()

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topHeight;
@property (weak, nonatomic) IBOutlet UILabel *topLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *replyBtnHeightLayout;
//@property (weak, nonatomic) IBOutlet NSLayoutConstraint *c2askCon;

@end


@implementation CTCConsultAnsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setTopText:(NSString *)topText
{
    _topText = [topText copy];
    _topLabel.text = _topText;
}

- (void)setHiddenTop:(BOOL)hiddenTop
{
    _hiddenTop = hiddenTop;
    if (_hiddenTop) {
        _topHeight.constant = 0.f;
        _topLabel.text = @"";
    } else {
        _topHeight.constant = 10.f;
    }
}


- (void)setShowBottom:(BOOL)showBottom
{
    _showBottom = showBottom;
    if (_showBottom) {
        
        self.replyBtnHeightLayout.constant = 30.f;
        [self.replyBtn setTitle:@"回复" forState:UIControlStateNormal];
        
    } else {
        
        
        self.replyBtnHeightLayout.constant = 0.f;
        [self.replyBtn setTitle:@"" forState:UIControlStateNormal];
    }
}


- (void)setIndex:(NSInteger)index
{
    _index = index;
    if (_index == 1) {
        self.hiddenTop = YES;
        self.topText = @"";
    } else {
        self.hiddenTop = NO;
        self.topText = (_index % 2) ? @"我的回答:" : @"用户追问:";
    }
    
    if (_answerModel) {
        [self setupContext];
    }
}


-(void)setAnswerModel:(CTCAnswerModel *)answerModel
{
    _answerModel = answerModel;
    self.contentLabel.text = answerModel.content;
    if (_index) {
        [self setupContext];
    }
    
    
//    // 当前阶段 ：0 初始  1 已回答 2 用户第一次追问 3咨询师回答了第一次追问 4 用户第二次追问 5 咨询师回答了第二次追问 6 用户第三次追问 7 咨询师回答了第三次追问  （0 2 4 6 时需要咨询师回答）
//    
//    BOOL isShowReplyBtn = ((self.answerModel.stage == 0)
//                           ||(self.answerModel.stage == 2)
//                           ||(self.answerModel.stage == 4)
//                           ||(self.answerModel.stage == 6)
//                           );
//    
//    if (isShowReplyBtn) {
//        self.replyBtnHeightLayout.constant = 0.f;
//        [self.replyBtn setTitle:@"" forState:UIControlStateNormal];
//    }
//    else {
//        self.replyBtnHeightLayout.constant = 30.f;
//        [self.replyBtn setTitle:@"回答" forState:UIControlStateNormal];
//    }
}

- (void)setupContext
{
//    self.showBottom = (self.answerModel.stage != 7) && (_index % 2) && (_index == self.answerModel.stage);
    
//    NSLog(@"self.answerModel：%@",[self.answerModel yy_modelDescription]);
    NSLog(@"_index：%ld",(long)_index);
//
//        
//    BOOL isNeedAnswer = ((self.answerModel.stage == 0)||(self.answerModel.stage == 2)||(self.answerModel.stage == 4)||(self.answerModel.stage == 6));
//    
//    if (!self.answerModel.firstAnswer) {
//        
//    }
//    
//    
//    
//    if (isNeedAnswer && !(_index%2) && (_index == self.addQuestionCout)) {
//        self.showBottom = YES;
//    }
//    else {
//        self.showBottom = NO;
//    }
    
    
    
    switch (_index) {
        case 1:
        {
            _contentLabel.text = self.answerModel.content;
            
            
            self.showBottom = NO;
            
        }
            
            
            break;
        case 2:
        {
            _contentLabel.text = self.answerModel.firstAsked;
            
            if (self.answerModel.firstAnswer && self.answerModel.firstAnswer.length) {
                self.showBottom = NO;
            } else {
                self.showBottom = YES;
            }
        }
            
            break;
        case 3:
        {
            _contentLabel.text = self.answerModel.firstAnswer;
            self.showBottom = NO;
        }
            
            break;
        case 4:
        {
            _contentLabel.text = self.answerModel.secondAsked;
            if (self.answerModel.secondAnswer && self.answerModel.secondAnswer.length) {
                self.showBottom = NO;
            } else {
                self.showBottom = YES;
            }
        }
            
            break;
        case 5:{
            _contentLabel.text = self.answerModel.secondAnswer;
            self.showBottom = NO;
        }
            
            break;
        case 6:{
            _contentLabel.text = self.answerModel.thirdAasked;
            
            if (self.answerModel.thirdAnswer && self.answerModel.thirdAnswer.length) {
                self.showBottom = NO;
            } else {
                self.showBottom = YES;
            }
        }
            
            break;
        case 7:
        {
            _contentLabel.text = self.answerModel.thirdAasked;
            self.showBottom = NO;
        }
            break;
        default:
            break;
    }
    
    
}
- (IBAction)replyBtnClick {
    if (self.replyBtnClickBlock) {
        self.replyBtnClickBlock();
    }
}


@end
